<route lang="json5">
{
  layout: 'default',
  style: {
    navigationBarTitleText: '样品交接',
    enablePullDownRefresh: false,
    navigationStyle: 'custom',
  },
}
</route>

<template>
  <page-meta :root-font-size="setting.rootFontSize"></page-meta>
  <view style="display: flex; flex-direction: column; height: 100vh; background-color: #f2f2f1">
    <view style="position: sticky; top: 0; z-index: 9999">
      <wd-navbar :title="`样品交接`" :bordered="false" safeAreaInsetTop>
        <template #left>
          <wd-icon name="thin-arrow-left" size="23px" color="white" @click="goBack"></wd-icon>
        </template>
		<template #right>
			<uni-print-button
				size="small"
				class="btn"
				type="text"
				kind="demand"
				:data="[{...form}]"
			 >
			 <view class="printer-icon"><wd-icon name="print" size="22px" color="white"></wd-icon>打印</view>
			 </uni-print-button>
		</template>
      </wd-navbar>
    </view>
    <view style="display: flex; flex: 1; flex-direction: column; height: 0">
      <view style="flex: 1; overflow: auto">
        <wd-form ref="formRef" :model="form" :rules="rules">
          <th-card title="需求单信息">
            <th-form>
              <th-form-item label="单据编号">
                <text class="text">{{ form.demandCode }}</text>
              </th-form-item>
              <th-form-item label="需求产品">
                <text class="text">{{ form.invName }}</text>
              </th-form-item>
              <th-form-item label="需求产品规格">
                <text class="text">{{ form.invStd }}</text>
              </th-form-item>
              <th-form-item label="需求评审结论" v-if="form.demandResult">
                <text class="text">{{ form.demandResult }}</text>
              </th-form-item>
            </th-form>
          </th-card>

          <th-card title="样品交接">
            <th-form-item label="推荐产品名称" v-if="demandform.recommendInvName">
              <text class="text">{{ demandform.recommendInvName }}</text>
            </th-form-item>
            <th-form-item label="推荐产品规格" v-if="demandform.recommendInvStd">
              <text class="text">{{ demandform.recommendInvStd }}</text>
            </th-form-item>
            <th-form-item label="样品批号">
              <wd-input
                type="text"
                v-model="form.sampleBatch"
                prop="sampleBatch"
                placeholder="请输入样品批号"
                no-border
                :disabled="
                  form.taskId ||
                  !(
                    form.status == 0 ||
                    form.status == null ||
                    form.status == 3 ||
                    form.status == 9
                  ) ||
                  form.closeFlag == '1'
                "
              />
            </th-form-item>

            <th-form-item label="样品数量">
              <!-- <wd-input
                type="text"
                v-model="form.sampleNum"
                prop="sampleNum"
                placeholder="请输入样品数量"
                no-border
                :disabled="
                  form.taskId ||
                  !(form.status == 0 || form.status == null || form.status == 3 || form.status == 9)
                "
              /> -->

              <view class="seq-no-text">
                <view style="display: flex; flex: 1">
                  <wd-input
                    type="number"
                    v-model="form.sampleNum"
                    prop="sampleNum"
                    placeholder="请输入样品数量"
                    style="flex: 1"
                    no-border
                    :disabled="
                      form.taskId ||
                      !(
                        form.status == 0 ||
                        form.status == null ||
                        form.status == 3 ||
                        form.status == 9
                      ) ||
                      form.closeFlag == '1'
                    "
                  />
                  {{ form.sampleNumUnit }}
                </view>
                <!-- <view>
                  <wd-picker
                    :columns="sampleUnitList"
                    label=""
                    placeholder=" "
                    v-model="form.sampleNumUnit"
                    @confirm="getSampleUnit"
                    size="mini"
                    custom-class="sample-unit-class"
                    custom-value-class="sample-unit-custom-value-class"
                    :disabled="
                      form.taskId ||
                      !(
                        form.status == 0 ||
                        form.status == null ||
                        form.status == 3 ||
                        form.status == 9
                      )
                    "
                  />
                </view> -->
              </view>
            </th-form-item>

            <th-form-item label="移交时间">
              <!-- <wd-datetime-picker
                prop="moveTime"
                type="datetime"
                v-model="form.moveTime"
                label=""
                :default-value="defaultValue"
                :disabled="
                  form.taskId ||
                  !(
                    form.status == 0 ||
                    form.status == null ||
                    form.status == 3 ||
                    form.status == 9
                  ) ||
                  form.closeFlag == '1'
                "
              ></wd-datetime-picker> -->
              <uni-datetime-picker
                type="datetime"
                v-model="form.moveTime"
                prop="moveTime"
                :border="false"
                :disabled="
                  form.taskId ||
                  !(
                    form.status == 0 ||
                    form.status == null ||
                    form.status == 3 ||
                    form.status == 9
                  ) ||
                  form.closeFlag == '1'
                "
              />
            </th-form-item>

            <th-form-item label="交接时间">
              <!-- <wd-datetime-picker
                prop="connectTime"
                type="datetime"
                v-model="form.connectTime"
                label=""
                :default-value="defaultValue"
                :disabled="
                  form.taskId ||
                  !(
                    form.status == 0 ||
                    form.status == null ||
                    form.status == 3 ||
                    form.status == 9
                  ) ||
                  form.closeFlag == '1'
                "
              ></wd-datetime-picker> -->
              <uni-datetime-picker
                type="datetime"
                v-model="form.connectTime"
                prop="connectTime"
                :border="false"
                :disabled="
                  form.taskId ||
                  !(
                    form.status == 0 ||
                    form.status == null ||
                    form.status == 3 ||
                    form.status == 9
                  ) ||
                  form.closeFlag == '1'
                "
              />
            </th-form-item>

            <th-form-item label="样品接受人">
              <view class="text seq-no-text" @click="showSelectUser">
                <wd-input
                  type="text"
                  readonly
                  prop="connectName"
                  v-model="form.connectName"
                  :placeholder="`请选择样品接受人`"
                  no-border
                />
              </view>
            </th-form-item>
          </th-card>

          <!-- <th-card title="需求指标" v-if="isShowCheckTarget">
            <wd-button
              :round="false"
              style="margin-bottom: 20rpx"
              @click="addCheckTargetList"
              type="text"
              v-if="
                !(
                  form.taskId ||
                  !(form.status == 0 || form.status == null || form.status == 3 || form.status == 9)
                )
              "
            >
              增行
            </wd-button>
            <view style="overflow: auto" class="table-container">
              <table class="analysis-table">
                <tbody>
                  <tr>
                    <th style="width: 320rpx; min-width: 9.5rem">检验指标名称</th>
                    <th style="width: 280rpx; min-width: 280rpx">U8指标</th>
                    <th style="width: 280rpx; min-width: 280rpx">客户指标</th>
                    <th
                      style="width: 280rpx; min-width: 280rpx"
                      v-if="
                        !(
                          form.taskId ||
                          !(
                            form.status == 0 ||
                            form.status == null ||
                            form.status == 3 ||
                            form.status == 9
                          )
                        )
                      "
                    >
                      操作
                    </th>
                  </tr>
                  <tr align="center" v-for="(item, index) in checkTargetList" :key="index">
                    <td>
                      <view
                        v-if="
                          form.taskId ||
                          !(
                            form.status == 0 ||
                            form.status == null ||
                            form.status == 3 ||
                            form.status == 9
                          )
                        "
                      >
                        {{ item.cchkguidename }}
                      </view>
                      <view v-else>
                        <wd-input
                          v-model="item.cchkguidename"
                          clearable
                          no-border
                          style="background-color: transparent"
                          placeholder="请输入检验指标名称"
                          :disabled="item.addFlag == 0"
                        ></wd-input>
                      </view>
                    </td>
                    <td>
                      <wd-input
                        v-model="item.checktarget"
                        clearable
                        no-border
                        style="background-color: transparent"
                        placeholder=" "
                        disabled
                      ></wd-input>
                    </td>
                    <td>
                      <view
                        v-if="
                          form.taskId ||
                          !(
                            form.status == 0 ||
                            form.status == null ||
                            form.status == 3 ||
                            form.status == 9
                          )
                        "
                      >
                        {{ item.cusCheckTarget }}
                      </view>
                      <template v-else>
                        <wd-input
                          v-model="item.cusCheckTarget"
                          clearable
                          no-border
                          style="background-color: transparent"
                          placeholder="请输入客户指标"
                        ></wd-input>
                      </template>
                    </td>

                    <td
                      v-if="
                        !(
                          form.taskId ||
                          !(
                            form.status == 0 ||
                            form.status == null ||
                            form.status == 3 ||
                            form.status == 9
                          )
                        )
                      "
                    >
                      <view>
                        <wd-button
                          :disabled="item.addFlag == 0"
                          type="text"
                          :style="{
                            color: item.addFlag == 0 ? 'gray' : 'red',
                          }"
                          @click="delRow(index, item)"
                        >
                          删除
                        </wd-button>
                      </view>
                    </td>
                  </tr>
                </tbody>
              </table>
            </view>
          </th-card> -->
        </wd-form>

        <th-card
          title="审核信息"
          v-if="form.status == '1' || form.status == '2' || form.status == '3'"
        >
          <view class="row-list">
            <view class="row" v-if="form.id && form.taskId">
              <!-- <view class="label">审核意见</view> -->
              <view class="value">
                <view class="mb2 mt2">
                  <h5>审核意见</h5>
                </view>
                <wd-textarea
                  type="textarea"
                  v-model="comment"
                  rows="6"
                  placeholder="请输入审核意见"
                  style="border: 1px solid #f7f7f7"
                ></wd-textarea>
              </view>
            </view>
            <view>
              <!-- <view class="mb2 mt2">
                  <h5>流转详情</h5>
                </view> -->
              <!-- <flowDetailsTable
                  ref="flowDetailsTableRef"
                  :processInstanceId="form.instanceId"
                  :key="new Date().getTime()"
                ></flowDetailsTable> -->
              <flowTable ref="flowDetailsTableRef" :processInstanceId="form.instanceId"></flowTable>
            </view>
          </view>
        </th-card>
      </view>

      <view class="flow-btn-fixed" v-if="form.id && form.taskId && form.closeFlag != '1'">
        <view class="btn_group" style="width: 100%">
          <view class="btn danger" @click="oncomplete(1)">
            <image src="../../../static/reject.png" class="btn-icon"></image>
            拒绝
          </view>
          <view class="btn primary" @click="oncomplete(0)">
            <image src="../../../static/tongyi.png" class="btn-icon"></image>
            同意
          </view>
        </view>
      </view>
      <view class="flow-btn-fixed" v-else>
        <view class="btn_group" style="width: 100%">
          <!-- <view class="btn danger" @click="onCancel()">取消</view> -->
          <view
            class="btn primary"
            @click="onSave()"
            v-if="
              !(
                form.taskId ||
                !(form.status == 0 || form.status == null || form.status == 3 || form.status == 9)
              ) &&
              checkPremiss('pm_rdConnect_add') &&
              form.closeFlag != '1'
            "
          >
            <image src="../../../static/save.png" class="btn-icon"></image>
            保存
          </view>
          <view
            class="btn primary"
            @click="onSubmit()"
            v-if="
              !(
                form.taskId ||
                !(
                  form.id &&
                  (form.status == null || form.status == 0 || form.status == 9 || form.status == 3)
                )
              ) &&
              checkPremiss('pm_rdConnect_check') &&
              form.closeFlag != '1'
            "
          >
            <image src="../../../static/submit.png" class="btn-icon"></image>
            提交
          </view>
          <view
            class="btn primary"
            @click="onRevokeShow()"
            v-if="
              !(form.taskId || !(form.id && form.status == 1)) &&
              checkPremiss('pm_rdConnect_check') &&
              form.closeFlag != '1'
            "
          >
            <image src="../../../static/rovoke.png" class="btn-icon"></image>
            撤回
          </view>
          <view
            class="btn primary"
            @click="onDel()"
            v-if="
              !(
                form.taskId ||
                !(
                  form.id &&
                  (form.status == 0 || form.status == null || form.status == 3 || form.status == 9)
                )
              ) &&
              checkPremiss('pm_rdConnect_del') &&
              form.closeFlag != '1'
            "
          >
            <image src="../../../static/del.png" class="btn-icon"></image>
            删除
          </view>
          <view
            class="btn primary"
            @click="onCancelApprover()"
            v-if="form.status == '2' && isCanCancelApprover && form.closeFlag != '1'"
          >
            <image src="../../../static/rovoke1.png" class="btn-icon"></image>
            弃审
          </view>
          <view
            class="btn primary"
            @click="rdDemandOpenHandle()"
            v-if="form.closeFlag == '1' && form.status == 0 && checkPremiss('pm_rdConnect_close')"
          >
            <image src="../../../static/open.png" class="btn-icon"></image>
            开启
          </view>
          <view
            class="btn primary"
            @click="closeDemandHandle()"
            v-if="form.closeFlag == '0' && form.status == 0 && checkPremiss('pm_rdConnect_close')"
          >
            <image src="../../../static/close.png" class="btn-icon"></image>
            关闭
          </view>
        </view>
      </view>
      <view style="width: 100; height: 10rpx; background-color: transparent"></view>
    </view>

    <leaguerPicker
      :show="selectUserShow"
      :filtration="true"
      :checked="selectList"
      :nop="1"
      :returnDeptName="true"
      @hideModal="hideModal"
      @checkLeaguer="checkLeaguer"
    ></leaguerPicker>
  </view>

  <wd-popup v-model="revokeShow" position="bottom" @close="handleClose">
    <view style="display: flex; flex-direction: column; height: 100%">
      <wd-textarea
        v-model="revokeComment"
        placeholder="请填写撤回原因"
        no-border
        prop="revokeComment"
        class="reovke-textarea"
      />
      <view class="flow-btn-fixed">
        <view class="btn_group" style="width: 100%">
          <view class="btn danger" @click="handleClose">取消</view>
          <view class="btn primary" @click="onRevoke">撤回</view>
        </view>
      </view>
    </view>
  </wd-popup>

  <wd-popup v-model="closeShow" position="bottom" @close="handleCloseResult">
    <view style="display: flex; flex-direction: column; height: 100%">
      <wd-textarea
        v-model="closeComment"
        placeholder="请填写关闭原因"
        no-border
        prop="revokeComment"
        class="reovke-textarea"
      />
      <view class="flow-btn-fixed">
        <view class="btn_group" style="width: 100%">
          <view class="btn danger" @click="handleCloseResult">取消</view>
          <view class="btn primary" @click="onClose">确定</view>
        </view>
      </view>
    </view>
  </wd-popup>
</template>

<script lang="ts" setup>
import { useSetting } from '@/stores/setting';
import {
  getObj,
  listLastNodePerson,
  selectTaskByProcessInstanceId,
  getPmDict,
} from '@/service/pm-requirement';
import {
  putrdConnect,
  submitrdConnectProcess,
  reviverdConnectProcess,
  delrdConnectObj,
  getrdConnectbj,
  revokerdConnectProcess,
  completerdConnect,
  getRdConnectPage,
  addrdConnect,
  closeProcess,
} from '@/service/connect-sample';
import { formatByDayjs } from '@/utils/util';
import { useUserStore } from '@/stores/user';
import { useDict } from '@/hooks/dict';
import flowDetailsTable from '@/task/components/flowDetailsTable.vue';
import cache from '@/utils/cache';
import showModal from '@/utils/modal';
import UniPrintButton from '@/pages/pm/assay-report/component/uniPrintButton.vue';

const setting = useSetting();
const minDate = ref(new Date().getTime());
const emits = defineEmits(['refresh']);
const tenantId = cache.getTenant();
const tenantName = cache.get('tenantName');
const userStore = useUserStore();
const flowDetailsTableRef: any = ref({});
const defaultValue = ref<number>(Date.now());
const sampleUnitList = ref([]);

// 提交表单数据
const demandform = reactive({
  id: null,
  status: null,
  demandDate: null,
  personName: null,
  demandType: undefined,
  demandTypeCode: undefined,
  deptHead: null,
  deptCode: null,
  applicationType: null,
  applicationCode: null,
  samplesNum: null,
  demandDesc: null,
  sampleCoding: null,
  askCompleteTime: null,
  taskCode: null,
  userCode: null,
  invName: null,
  invDemand: null,
  sampleFlag: '0',
  demandCode: null,
  cusName: null,
  personCode: null,
  deptHeadCode: null,
  cusFlag: '0',
  invStd: null,
  sampleCode: null,
  sampleBatch: null,
  deptName: null,
  tenantId: null,
  deptId: null,
  sampleFlagName: '否',
  cusCode: null,
  cusId: null,
  sampleUnit: null,
  sampleUnitCode: null,
  instanceId: null,
  taskId: null,
  rdFlag: null,
  createBy: null,
  createName: null,
  createTime: null,
  updateBy: null,
  delFlag: null,
  updateName: null,
  updateTime: null,
  deputyChiefEngineer: null,
  deputyChiefEngineerName: null,
  deputyChiefEngineerPost: null,
  deputyChiefEngineerUrl: null,

  chiefEngineer: null,
  chiefEngineerPost: null,
  chiefEngineerUrl: null,
  chiefEngineerName: null,
  tenantName: null,
  reviewStatus: null,
  samplesNumUnit: null,
  demandId: null,

  // 任务
  projectCode: null,
  projectName: null,
  projectHeadName: null,
  projectHead: null,
  technologyHead: null,
  technologyHeadName: null,
  technologyHeadCode: null,
  taskDate: null,
  rdProjectUserEntity: [],
  completionTime: null,
  rdCraftEntity: [],
  rdSampleAnalysisEntity: [],
  rdInformationDTO: [],
  rdPlan: null,
  requirements: null,
  sampleReviewConclusion: null,
  taskAllStatus: '1',
  signed: null,
  signedCode: null,
  signedName: null,
  demandResult: null,
  recommendInvName: null,
  recommendInvStd: null,
});

// 提交表单数据
const form = reactive({
  id: '',
  connectTime: null,
  moveTime: null,
  sampleBatch: null,
  sampleNum: null,
  demandId: null,
  demandCode: null,
  connectName: null,
  connectUser: null,
  connectPerson: null,
  status: null,
  instanceId: null,
  taskId: null,
  rdFlag: null,
  sampleNumUnit: null,
  sampleNumUnitCode: null,
  closeFlag: '0',
  invName: null,
  invStd: null,
  demandResult: null,
});

const init = (id) => {
  uni.showLoading({
    mask: true,
  });
  getrdConnectbj(id)
    .then((res) => {
      console.log('res', res);
      if (res.code == 0) {
        Object.assign(form, res.data);

        if (res.data.map) {
          demandform.recommendInvName = res.data.map.recommend_inv_name;
          demandform.recommendInvStd = res.data.map.recommend_inv_std;
        }

        if (res.data.instanceId) {
          selectTaskByProcessInstanceId({
            processInstanceId: res.data.instanceId,
          })
            .then((res) => {
              form.taskId = res.data && res.data.taskId ? res.data.taskId : null;
            })
            .catch(() => {
              form.taskId = null;
            });
          getCancelApprover();
          console.log('form', form);
          nextTick(() => {
            flowDetailsTableRef.value.getFlowDetails();
          });
        }
        form.connectTime = form.connectTime ? new Date(form.connectTime) : null;
        form.moveTime = form.moveTime ? new Date(form.moveTime) : null;

        form.connectName = form.connectName || res.data.personName;
        form.connectUser = form.connectUser || res.data.personCode;
        form.connectPerson = form.connectPerson || null;

        form.sampleNum = form.sampleNum || res.data.requestNum;
        form.sampleNumUnitCode = form.sampleNumUnitCode || res.data.requestNumUnitCode || 'g';
        form.sampleNumUnit = form.sampleNumUnit || res.data.requestNumUnit || 'g';

        // getNeedId(res.data.demandId);
      } else {
        uni.showToast({
          mask: true,
          icon: 'none',
          title: `获取数据失败，失败原因${res.msg}`,
        });
      }
    })
    .finally(() => {
      uni.hideLoading();
    });
};
onLoad(async (options) => {
  const { id, needId, demandCode } = options;
  await getPmDict({ dictType: 'pm_need_unit', pageSize: -1 }).then((res) => {
    sampleUnitList.value = res.data.records;
  });

  if (id) {
    init(id);
  } else {
    // getNeedId(needId);
    form.demandId = needId;
    form.demandCode = demandCode;
  }
});

const getNeedId = (needid) => {
  uni.showLoading({
    mask: true,
  });
  getObj({ id: needid })
    .then((res) => {
      console.log('res', res);
      if (res.code == 0) {
        Object.assign(demandform, res.data);

        form.connectName = form.connectName || res.data.personName;
        form.connectUser = form.connectUser || res.data.personCode;
        form.connectPerson = form.connectPerson || null;
        form.sampleNum = form.sampleNum || res.data.requestNum;
        form.sampleNumUnitCode = form.sampleNumUnitCode || res.data.requestNumUnitCode || 'g';
        form.sampleNumUnit = form.sampleNumUnit || res.data.requestNumUnit || 'g';
      } else {
        uni.showToast({
          mask: true,
          icon: 'none',
          title: `获取数据失败，失败原因${res.msg}`,
        });
      }
    })
    .finally(() => {
      uni.hideLoading();
    });
};

const goBack = () => {
  uni.navigateBack();
};

const selectUserShow = ref(false);
const selectList = ref([]);
const hideModal = () => {
  selectUserShow.value = false;
};
const checkLeaguer = (e) => {
  form.connectUser = e[0].personCode;
  form.connectName = e[0].personName;
  form.connectPerson = e[0].id;
};
const showSelectUser = () => {
  if (
    form.taskId ||
    !(form.status == 0 || form.status == null || form.status == 3 || form.status == 9) ||
    form.closeFlag == '1'
  ) {
    return;
  }
  selectUserShow.value = true;
};

const rules: any = computed(() => {
  return {
    sampleBatch: [{ required: true, message: '样品批号不能为空' }],
    sampleNum: [{ required: true, message: '样品数量不能为空' }],
    moveTime: [{ required: true, message: '移交时间不能为空' }],
    connectTime: [{ required: true, message: '交接时间不能为空' }],
    connectName: [{ required: true, message: '样品接受人不能为空' }],
  };
});

const onCancel = () => {
  uni.navigateBack({});
};

const formRef: any = ref({});
const onSave = (isSubmit = false) => {
  // formRef.value.validate().then(({ valid, errors }) => {
  //   debugger;
  //   if (!valid) return false;

  if (!form.sampleBatch) {
    uni.showToast({
      mask: true,
      icon: 'none',
      title: '样品批号不能为空',
    });
    return false;
  }
  if (!form.sampleNum) {
    uni.showToast({
      mask: true,
      icon: 'none',
      title: '样品数量不能为空',
    });
    return false;
  }
  if (!form.moveTime) {
    uni.showToast({
      mask: true,
      icon: 'none',
      title: '移交时间不能为空',
    });
    return false;
  }
  if (!form.connectTime) {
    uni.showToast({
      mask: true,
      icon: 'none',
      title: '交接时间不能为空',
    });
    return false;
  }
  if (!form.connectName) {
    uni.showToast({
      mask: true,
      icon: 'none',
      title: '样品接受人不能为空',
    });
    return false;
  }

  uni.showLoading({
    mask: true,
  });

  const params = {
    ...form,
  };

  params.moveTime = form.moveTime ? formatByDayjs(form.moveTime, 'YYYY-MM-DD HH:mm:ss') : '';
  params.connectTime = form.connectTime
    ? formatByDayjs(form.connectTime, 'YYYY-MM-DD HH:mm:ss')
    : '';
  (form.id ? putrdConnect(params) : addrdConnect(params))
    .then((res) => {
      // uni.navigateBack();
      if (res.code == 0) {
        if (isSubmit) {
          submitrdConnectProcessHandle();
        } else {
          uni.showToast({
            mask: true,
            title: `保存成功`,
            icon: 'none',
          });
          setTimeout(() => {
            init(form.id || res.data.id);
          }, 500);
        }
      } else {
        uni.showToast({
          mask: true,
          title: `保存失败，失败原因${res.msg}`,
          icon: 'none',
        });
      }
    })
    .finally(() => {
      uni.hideLoading();
    });
  // });
};

const onSubmit = () => {
  showModal({
    title: '提示',
    content: '是否提交该单据',
    showCancel: true,
    confirm: () => {
      onSave(true);
    },
  });
};

const submitrdConnectProcessHandle = () => {
  uni.showLoading({
    mask: true,
  });
  submitrdConnectProcess(form.id)
    .then((res) => {
      if (res.code == 0) {
        uni.showToast({
          mask: true,
          title: `提交成功`,
          icon: 'none',
        });
        init(form.id);
      } else {
        uni.showToast({
          mask: true,
          title: `提交失败，失败原因：${res.msg}`,
          icon: 'none',
        });
      }
    })
    .finally(() => {
      uni.hideLoading();
    });
};

const onDel = () => {
  showModal({
    title: '提示',
    content: '是否删除该单据',
    showCancel: true,
    confirm: () => {
      uni.showLoading({
        mask: true,
      });
      delrdConnectObj([form.id])
        .then((res) => {
          if (res.code == 0) {
            uni.showToast({
              mask: true,
              title: `删除成功`,
              icon: 'none',
            });
            // const pages = getCurrentPages();
            // const prevPage = pages[pages.length - 2]; // 上一个页面
            // prevPage.$vm.refresh();
            goBack();
            uni.$emit('refresh');
          } else {
            uni.showToast({
              mask: true,
              title: `删除失败，失败原因：${res.msg}`,
              icon: 'none',
            });
          }
        })
        .finally(() => {
          uni.hideLoading();
        });
    },
  });
};

// 撤回
const revokeComment = ref('');
const revokeShow = ref(false);
const handleClose = () => {
  revokeShow.value = false;
};
const onRevoke = () => {
  showModal({
    title: '提示',
    content: '是否撤回该单据',
    showCancel: true,
    confirm: () => {
      uni.showLoading({
        mask: true,
      });
      revokerdConnectProcess({
        id: form.id,
        instanceId: form.instanceId,
        comment: revokeComment.value,
      })
        .then((res) => {
          if (res.code == 0) {
            uni.showToast({
              mask: true,
              title: `撤回成功`,
              icon: 'none',
            });
            handleClose();
            init(form.id);
          } else {
            uni.showToast({
              mask: true,
              title: `撤回失败，失败原因：${res.msg}`,
              icon: 'none',
            });
          }
        })
        .finally(() => {
          uni.hideLoading();
        });
    },
  });
};
const onRevokeShow = () => {
  revokeShow.value = true;
};

// 审核信息
const comment = ref('');
const oncomplete = (type) => {
  if (type == '1' && !comment.value) {
    uni.showToast({
      title: '请填写审核意见',
      icon: 'none',
      mask: true,
    });
    return;
  }

  const params = {
    // ...form,
    taskId: form.taskId,
    comment: comment.value,
    id: form.id,
    approve: type == 0,
  };
  uni.showLoading({
    mask: true,
  });
  completerdConnect(params, form.id)
    .then((res) => {
      if (res.code == 0) {
        uni.showToast({
          title: '单据审核成功',
          icon: 'none',
          mask: true,
        });
        // uni.navigateBack({});
        form.instanceId = '';
        init(form.id);
        uni.$emit('refresh');
        // nextTick(() => {
        //   flowDetailsTableRef.value.getFlowDetails();
        // });
      } else {
        uni.showToast({
          mask: true,
          title: `单据审核失败，失败原因：${res.msg}`,
          icon: 'none',
        });
      }
    })
    .finally(() => {
      uni.hideLoading();
    });
};

const preview = (url) => {
  if (!url) return;
  uni.previewImage({
    urls: [url],
  });
};

const isCanCancelApprover = ref(false); // 是否能弃审
const getCancelApprover = () => {
  listLastNodePerson({
    processInstanceId: form.instanceId,
  })
    .then((res) => {
      const dataList = res.data;
      const { username } = userStore.userInfos.user;
      if (dataList.find((item) => item == username)) {
        isCanCancelApprover.value = true;
      } else {
        isCanCancelApprover.value = false;
      }
    })
    .finally(() => {});
};

const onCancelApprover = () => {
  showModal({
    title: '提示',
    content: '是否弃审该单据',
    showCancel: true,
    confirm: () => {
      uni.showLoading({
        mask: true,
      });
      reviverdConnectProcess(form.id)
        .then((res) => {
          if (res.code == 0) {
            uni.showToast({
              mask: true,
              title: `弃审成功`,
              icon: 'none',
            });
            form.instanceId = '';
            init(form.id);
            // nextTick(() => {
            //   flowDetailsTableRef.value.getFlowDetails();
            // });
          } else {
            uni.showToast({
              mask: true,
              title: `弃审失败，失败原因：${res.msg}`,
              icon: 'none',
            });
          }
        })
        .finally(() => {
          uni.hideLoading();
        });
    },
  });
};

const previewFileHandle = (file) => {
  uni.navigateTo({
    url: '/pages/pm/preview-online?url=' + file,
  });
};

const checkPremiss = (k) => {
  return userStore.userInfos.authBtnList.some((v: string) => v === k);
};

const getSampleUnit = (e) => {
  form.sampleNumUnitCode = e.selectedItems.label;
  form.sampleNumUnit = e.value;
};

const rdDemandOpenHandle = () => {
  showModal({
    title: '提示',
    content: '是否开启该单据',
    showCancel: true,
    confirm: () => {
      uni.showLoading({
        mask: true,
      });
      closeProcess({
        id: form.id,
        closeFlag: 0,
        demandCode: form.demandCode,
      })
        .then((res) => {
          if (res.code == 0) {
            uni.showToast({
              mask: true,
              title: `开启成功`,
              icon: 'none',
            });
            form.instanceId = '';
            init(form.id);
            // nextTick(() => {
            //   flowDetailsTableRef.value.getFlowDetails();
            // });
          } else {
            uni.showToast({
              mask: true,
              title: `开启失败，失败原因：${res.msg}`,
              icon: 'none',
            });
          }
        })
        .finally(() => {
          uni.hideLoading();
        });
    },
  });
};

const closeComment = ref('');
const closeShow = ref(false);
const handleCloseResult = () => {
  closeShow.value = false;
};
const onClose = () => {
  if (!closeComment.value) {
    uni.showToast({
      title: '关闭原因不能为空',
      icon: 'none',
      mask: true,
    });
    return;
  }

  showModal({
    title: '提示',
    content: '是否关闭该单据',
    showCancel: true,
    confirm: () => {
      uni.showLoading({
        mask: true,
      });
      closeProcess({
        id: form.id,
        closeReason: closeComment.value,
        closeFlag: 1,
        demandCode: form.demandCode,
      })
        .then((res) => {
          if (res.code == 0) {
            uni.showToast({
              mask: true,
              title: `关闭成功`,
              icon: 'none',
            });
            handleCloseResult();
            init(form.id);
          } else {
            uni.showToast({
              mask: true,
              title: `关闭失败，失败原因：${res.msg}`,
              icon: 'none',
            });
          }
        })
        .finally(() => {
          uni.hideLoading();
        });
    },
  });
};
const closeDemandHandle = () => {
  closeShow.value = true;
};
</script>

<style lang="scss" scoped>
@import '../experiment/components/table';

.card-detail {
  padding: 0 !important;
}

.wd-cell {
  padding-left: 0 !important;
}

.wd-card__title {
  border-left: 4px solid #2e5cf6 !important;
}

.pm-table {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  padding: 0 30rpx;

  .pm-title {
    box-sizing: border-box;
    padding-left: 20rpx;
    margin: 40rpx 0;
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
    border-left: 8rpx solid #2e5cf6;
    border-radius: 4rpx;
  }

  .pm-row {
    display: flex;
    min-height: 60rpx;
    border-bottom: 1px solid #f6f0f0;

    .pm-label {
      display: flex;
      align-items: center;
      width: 20%;
      font-size: 26rpx;
      color: #979494;
    }

    .pm-value {
      display: flex;
      flex: 1;
      align-items: center;
      font-size: 26rpx;
      color: #333;
    }
  }
}

.sign-main {
  // display: flex;
  // align-items: center;
  // justify-content: center;
  // width: 100%;
  // margin: 20rpx 0;
  position: fixed;
  right: 0rpx;
  bottom: 40rpx;
  width: 160rpx;
  height: 80rpx;
  line-height: 80rpx;
  color: white;
  text-align: center;
  background-color: rgb(77 128 240);

  // border-radius: 50%;
  border-top-left-radius: 40rpx;
  border-bottom-left-radius: 40rpx;
}

:deep(.label) {
  width: 160rpx !important;
}

.result-tag {
  padding: 6rpx 14rpx;
  font-size: 24rpx;
  color: white;
  background-color: #87d068;
  border-radius: 4rpx;
}

:deep(.wd-picker__cell) {
  padding: 0 !important;

  // padding: 0 20rpx !important;
  // font-size: 26rpx !important;
}

:deep(.wd-select-picker__cell) {
  padding: 0 !important;
}

// .wd-picker__value-wraper {
//   .wd-icon {
//     display: none !important;
//   }
// }

.seq-no-text {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.flow-btn-fixed {
  width: 100%;
  background-color: white;
  border-top: 1px solid #f2f2f1;
}

.btn_group {
  display: flex;
  justify-content: space-between;

  // margin: 0rpx 0 20rpx;
  // border-bottom: 1px solid #f2f2f1;

  .btn {
    display: flex;

    // width: 49%;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    // height: 40px;
    min-height: 40px;
    padding: 10rpx 0;
    font-size: 24rpx;
    color: black;

    // background-color: white !important;
    background-color: #dbecff !important;
    border-left: 1px solid #f7f7f7;
    border-radius: 0 !important;

    // color: white;
    border-radius: 6rpx;

    .btn-icon {
      width: 40rpx;
      height: 40rpx;
      margin-bottom: 8rpx;
    }
  }

  .danger {
    background-color: #f56c6c;
  }

  .primary {
    background-color: #409eff;
  }
}

.form-demandDesc {
  align-items: flex-start !important;
}
</style>
<style lang="scss">
/* .sample-unit-class {
    color: #9d9999 !important;
  
    .wd-icon {
      display: none !important;
    }
  
    .wd-picker__placeholder {
      margin-right: 0 !important;
      font-size: 20rpx !important;
      color: #9d9999 !important;
    }
  
    .wd-picker__value {
      margin-right: 0 !important;
      font-size: 20rpx !important;
      color: #9d9999 !important;
    }
  
    .wd-picker__arrow {
      display: none !important;
    }
  } */

.wd-picker,
.wd-select-picker {
  width: 100%;
}

.wd-textarea::after {
  height: 0;
}

:deep(.wd-picker__placeholder) {
  font-size: 28rpx !important;
  color: #bfbfbf !important;
}

:deep(.wd-input__placeholder) {
  font-size: 28rpx !important;
  color: #bfbfbf !important;
}

:deep(.wd-textarea__placeholder) {
  font-size: 28rpx !important;
  color: #bfbfbf !important;
}

.sample-unit-custom-value-class .wd-picker__placeholder {
  font-size: 20rpx !important;
  color: #bfbfbf !important;
}

.sample-unit-class {
  .wd-picker__placeholder {
    margin-right: 0 !important;
    font-size: 24rpx !important;
  }

  .wd-icon {
    display: none !important;
  }
}

:deep(.wd-picker__value) {
  color: #262626 !important;
}

:deep(.uni-input-input) {
  color: #262626 !important;
}

:deep(.wd-select-picker__value) {
  color: #262626 !important;
}

:deep(.uni-textarea-compute) {
  div {
    color: #262626 !important;
  }

  color: #262626 !important;
}

:deep(.uni-textarea-textarea) {
  color: #262626 !important;
}

:deep(.wd-textarea.is-auto-height::after) {
  display: none;
}

.reovke-textarea {
  box-sizing: border-box;
  flex: 1 !important;
  padding: 20rpx !important;

  :deep(.wd-textarea__value) {
    height: 100% !important;
  }
}

:deep(.wd-textarea.is-not-empty:not(.is-disabled)::after) {
  background-color: transparent !important;
}

.text {
  word-break: break-all;
  word-wrap: break-word;
}

.title_box .title_text {
  padding-left: 0 !important;
  margin-top: 10rpx !important;
}

.form-file {
  flex-direction: column;

  .label {
    width: 3rem !important;
  }

  .form-file-view {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;

    uni-button {
      margin: 5rpx 0 !important;
    }
  }
}

.info-row-item {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 6rpx 0;
  color: blue;
  word-break: break-all;
}

:deep(.wd-col-picker__cell) {
  padding: 0 !important;
}

:deep(.uni-date__x-input) {
  line-height: normal !important;
}

:deep(.uni-date-editor) {
  background-color: transparent !important;
}

:deep(.uni-date-editor--x__disabled) {
  opacity: 1 !important;

  .uni-date__x-input {
    color: #262626 !important;
  }
}

:deep(.wd-navbar__right--hover) {
  background: none!important;
}
.printer-icon{
	display: flex;
	item-align:center;
	color:#fff;
}
</style>
